package com.cvte.boe.media.utils;

import com.cvte.boe.media.model.LocalDeviceInfo;

import java.io.File;
import java.util.Comparator;

/**
 * Created by wuguitong on 2018/4/18.
 */
public class ComparatorUtil {
    public static class LocalDevComparator implements Comparator<LocalDeviceInfo> {
        @Override
        public int compare(LocalDeviceInfo t0, LocalDeviceInfo t1) {
            return t0.getDevName().compareTo(t1.getDevName());
        }
    }

    public static class MediaFileComparator implements Comparator<File> {
        @Override
        public int compare(File file1, File file2) {
            int result = -1;
            if ((!file1.exists()) || (!file2.exists())) {
                return result;
            }
            if (file1.isDirectory() && file2.isFile()) {
                result = -1;
            } else if (file1.isFile() && file2.isDirectory()) {
                result = 1;
            } else {
                result = file1.getName().compareTo(file2.getName());//ustrcasecmp(returnString(file1.getName(), 0), returnString(file2.getName(), 0));
                if (result > 0) {
                    result = 1;
                } else if (result < 0) {
                    result = -1;
                }
            }
            return result;
        }
    }

}
